//
//  FirstCustomesugue.swift
//  Transition
//
//  Created by Open on 2/3/15.
//  Copyright (c) 2015 open-groupe. All rights reserved.
//

import UIKit

class FirstCustomesugue: UIStoryboardSegue {
    
    override func   perform() {
        var firstView = self.sourceViewController.view as UIView!
        var secondView = self.destinationViewController.view as UIView!
        
        let screenWidth = UIScreen.mainScreen().bounds.size.width
        let screenHeight = UIScreen.mainScreen().bounds.size.height
        
        secondView.frame = CGRectMake(0, screenHeight, screenWidth,screenHeight)
        
        let window = UIApplication.sharedApplication().keyWindow
        window?.insertSubview(secondView, aboveSubview: firstView)
        
        UIView.animateWithDuration(0.5, animations: {() -> Void in
                    firstView.frame = CGRectOffset(firstView.frame, 0, -screenHeight)
                    secondView.frame = CGRectOffset(secondView.frame, 0, -screenHeight)
        })
            {(Finished) -> Void in
                    self.sourceViewController.presentViewController(self.destinationViewController as UIViewController, animated: false, completion: nil)
                
        }
        
    }

}
